/**
 * Copyright (c): eyjo.
 * Author: eyjo
 * Date: 26.11.2011
 * Time: 13:04
 * Description:
 */

import com.sun.org.apache.xpath.internal.operations.Bool;
import org.uispec4j.*;
import org.uispec4j.Button;
import org.uispec4j.Window;
import org.uispec4j.interception.MainClassAdapter;
import org.uispec4j.xml.XmlAssert;

import javax.swing.*;
import java.awt.*;

public class GUItest extends UISpecTestCase
{
    private Window mainWindow;
    private JFrame mainFrame;

    static{
        UISpec4J.init();
    }

    protected void setUp() throws Exception
    {
        System.out.println(" *** restAddSuccess() is being called *** ");
        setAdapter(new MainClassAdapter(TicTacToe.class, new String[0]));
        mainWindow = getMainWindow();
    }

    public void testTitle() throws Exception
    {
        System.out.println(" *** testTitle() is being called *** ");
        System.out.println("Ans > " + mainWindow.getButton("1").getDescription());
        assertEquals("Silver bullets awesome Tic Tac Toe game!", mainWindow.getTitle());
    }

    public void testButton() throws Exception
    {
        System.out.println(" *** testButton is being called ***");


        Button button = mainWindow.getButton("0");
        assertEquals("0", button.getName());
        button.click();
        System.out.println(button.getName());

        Boolean buttonValue = false;
        buttonValue = button.getAwtComponent().getIcon().toString().contains("X.png");
        assertTrue("Button has changed from 0 to x", buttonValue);

    }
      //assert x and o are called
    public void testButtons() throws Exception
    {
        System.out.println(" *** testButtons is being called *** ");

        Button buttonX = mainWindow.getButton("0");
        buttonX.click();
        Button buttonO = mainWindow.getButton("1");
        buttonO.click();

        Boolean buttonValue = false;
        buttonValue = buttonO.getAwtComponent().getIcon().toString().contains("O.png");
        assertTrue("Button has changed from 0 to O", buttonValue);

    }


    protected void tearDown()
    {
        System.out.println(" *** tearDown() is being called *** ");
        mainWindow = null;
    }
}
